Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.TT_RecorderManager = undefined;
var $2EventCenter = require("EventCenter");
var $2UIHelp = require("UIHelp");
var s = window.tt;
var exp_TT_RecorderManager = /* */function () {
  function _ctor() {
    babel_classCallCheck(this, _ctor);
    this.recorder = null;
    this.videoPath = null;
    this.getvideo = false;
    this.viodeTime = 0;
    this.recordering = false;
    this.active = !s || "devtools" == s.getSystemInfoSync().appName;
  }
  return babel_createClass(_ctor, [{
    key: "start",
    value: function start() {
      var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 280;
      if (s && !this.active) {
        this.recordering = true;
        this.viodeTime = 0;
        console.log("......开始录屏......", this.recorder);
        this.recorder.start({
          duration: e
        });
      }
    }
  }, {
    key: "initGameRecorderManager",
    value: function initGameRecorderManager() {
      var _this86 = this;
      if (s && !this.active) {
        this.recorder = s.getGameRecorderManager();
        this.recorder.onStop(function (e) {
          _this86.onStop(e);
        });
      }
    }
  }, {
    key: "onStop",
    value: function onStop(e) {
      this.recordering = false;
      var t = this;
      this.videoPath = "";
      this.getvideo = false;
      console.log("onStop", this.viodeTime);
      console.log("res", e);
      if (this.viodeTime > 0) {
        this.recorder.clipVideo({
          path: e.videoPath,
          timeRange: [3, 0],
          success(e) {
            t.videoPath = e.videoPath;
            console.log("videoPath", t.videoPath);
            $2EventCenter.default.postWaitEvent("playvideo", e.videoPath);
            1 == t.getvideo && console.log(e.videoPath);
          }
        });
      } else {
        this.recorder.clipVideo({
          path: e.videoPath,
          timeRange: [120, 0],
          success(e) {
            t.videoPath = e.videoPath;
            $2EventCenter.default.postWaitEvent("playvideo", e.videoPath);
            1 == t.getvideo && console.log(e.videoPath);
          },
          fail(e) {
            console.log("clipVideoFail:", e);
          }
        });
      }
    }
  }, {
    key: "recordClip",
    value: function recordClip(e) {
      if (s && !this.active) {
        this.viodeTime += e[0] + e[1];
        console.log("recordClip", e);
        this.recorder.recordClip({
          timeRange: e
        });
      }
    }
  }, {
    key: "shareAppMessage",
    value: function shareAppMessage(e, t) {
      if (!s || this.active || 1 == this.recordering) {
        return void (e && e(false));
      }
      console.log("抖音开始分享", t);
      t && "" != t.videoPath && null != t.videoPath && null != t.videoPath && (this.videoPath = t.videoPath);
      if ("" == this.videoPath) {
        e && e(false);
        return void console.log("录屏资源不存在！");
      }
      var n = {
        videoPath: this.videoPath,
        videoTopics: ["消除天花板", "物理消除", "烧脑"],
        withVideoId: true
      };
      s.shareAppMessage({
        channel: "video",
        extra: n,
        success(t) {
          console.log("分享视频成功", t);
          e && e(true);
        },
        fail(t) {
          "shareAppMessage:cancel" == t.errMsg || t.errMsg;
          console.log("分享视频失败", t);
          $2UIHelp.UIHelp.showTip("分享视频失败");
          e && e(false);
        }
      });
    }
  }, {
    key: "navigateToVideoView",
    value: function navigateToVideoView(e) {
      s && !this.active && s.navigateToVideoView({
        videoId: e,
        success() {
          console.log("done");
        },
        fail(e) {
          1006 === e.errCode && s.showToast({
            title: "something wrong with your network"
          });
        }
      });
    }
  }, {
    key: "request",
    value: function request(e, t) {
      s.request({
        url: "https://gate.snssdk.com/developer/api/get_video_info",
        method: "POST",
        data: {
          alias_ids: e
        },
        success(e) {
          t && t(e);
        },
        fail(e) {
          t && t(e);
        }
      });
    }
  }, {
    key: "shareVideo",
    value: function shareVideo(e) {
      if (s && !this.active) {
        if (1 != this.recordering) {
          if ("" != this.videoPath) {
            s.shareVideo({
              videoPath: "".concat(this.videoPath),
              success() {
                console.log("分享成功！");
                e && e(true);
              },
              fail(t) {
                console.log("分享失败！");
                e && e(false);
              }
            });
          } else {
            this.getvideo = true;
          }
        }
      } else {
        e && e(true);
      }
    }
  }, {
    key: "stop",
    value: function stop() {
      if (s && !this.active) {
        console.log("---------结束录制---------");
        this.recorder.stop();
      }
    }
  }, {
    key: "pause",
    value: function pause() {
      s && !this.active && this.recorder.pause();
    }
  }, {
    key: "resume",
    value: function resume() {
      s && !this.active && this.recorder.resume();
    }
  }], [{
    key: "getInstance",
    value: function getInstance() {
      if (null == this._instance) {
        this._instance = new _ctor();
        this._instance.initGameRecorderManager();
      }
      return this._instance;
    }
  }]);
}();
exports.TT_RecorderManager = exp_TT_RecorderManager;
exp_TT_RecorderManager._instance = null;